package com.yan.demo1;

import java.util.Random;
import java.util.concurrent.CountDownLatch;

/**
 * @author taoge
 * @Date 2024/8/9 9:34
 * @Description join（）改写方法
 */
public class Demo1 {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(new Random().nextInt(2001) + 1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName() + "离开了教室");

            }
        };



        new Thread(new Runnable() {
            @Override
            public void run() {

                for (int i = 1; i <= 10; i++) {
                    Thread t = new Thread(runnable, "学生" + i);
                    t.start();
                    try {
                        t.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                System.out.println(Thread.currentThread().getName() + "关门了");
            }
        } , "门卫").start();

    }
}
